import redis from "../db/cache.js";
import { queryUserByUserName } from "../service/user.js";

export async function confirmAccount(req, res, next){
  const result = await queryUserByUserName(req.body.account)
  if(result.length){
    res.send({resCode: 100, message:'账号已存在'})
    return
  }
  next()
}

export async function confirmSession(req, res, next){
  if(req.headers.authorization){
    const session = await redis.get(req.headers.authorization)
    if(session){
      next()
    }else{
      res.send({isValid: false})
      return
    }
  }else{
    next()
  }
}
